<template>
  <div class="ancestral" v-if="data.length"> 
    <div class="ancestral-title"></div>

    <div class="ancestral-content">
      <div class="cnt-title">{{ data[initialSlide].name }}</div>
      <div class="cnt-text">
        {{ data[initialSlide].intro }}
      </div>
      <div class="ancestral-more">
        <a :href="data[initialSlide].linkUrl" alt="" target="_blank"> 【查看详情】</a>
      </div>
    </div>

    <div class="books-list" >
      <Swiper
        :slides-per-view="9"
        :modules="[ $SwiperModules.Navigation]"
        :navigation="{ nextEl: '.custom-next', prevEl: '.custom-prev' }"
        @swiper="onSwiper"
        loop
        :speed="800"
        @slideChange="onSlideChange"
        class="swiper-wrapper"
      >
        <SwiperSlide class="book-slide" v-for="(item,index) in data" :key="index">
          <a class="books-item" :href="item.linkUrl" target="_blank" @mouseover="onHover(index)">
            <div class="books-item-mian">
              <div class="books-title">{{item.name.slice(0,7)}}<br><span style="line-height:2px" v-if="item.name.length>7">…</span></div>
            </div>
          </a>
        </SwiperSlide>
      </Swiper>
      <div class="custom-prev"></div>
      <div class="custom-next"></div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, watch, onBeforeUnmount } from 'vue'
const props = defineProps({
  data: {
    type: Array,
    default: []
  },
})
 const onSwiper = (swiper) => {
    console.log(swiper);
  };
  const onSlideChange = () => {
    console.log('slide change');
  };

  const initialSlide = ref(0)
  
  const onHover = (index) => { 
    initialSlide.value = index
  };

</script>
<style lang="scss" scoped>
.ancestral{
  height: 800px;
  background: url('@/assets/images/ancestral-bg.png') no-repeat center center;
  display: flex;
  flex-direction: column;
  align-items: center;
  .ancestral-title{
    width: 814px;
    height: 77px;
    background: url('@/assets/images/ancestral-title.png') no-repeat;
    align-self: flex-start;
    margin-top: 85px;
  }
  .ancestral-content{
    width: 1280px;
    margin-top: 89px;
    height: 202px;
    .cnt-title{
      font-weight: 500;
      font-size: 30px;
      color: #111111;
      line-height: 42px;
      
    }
    .cnt-text{
      font-weight: 400;
      font-size: 18px;
      color: #393329;
      line-height: 34px;
      margin-top: 24px;
      

      // 添加以下样式实现6行省略号效果
      display: -webkit-box;
      -webkit-line-clamp: 4;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .ancestral-more{
      display: flex;
      justify-content: flex-end;
      a{
        color: #B52628;
      }
    }
  }


  .books-list{
    margin-top: 98px;
    width: 1200px;
    position: relative;
    .book-slide{
      display: flex;
      justify-content: center;
    }
    .books-item{
      padding: 2px;
      border: 1px solid transparent;
      &:hover{ 
        border: 1px solid #B52628;
        .books-item-mian{
          background: url('@/assets/images/book-bg2.png');
        }
      }
    }
    .books-item-mian{
      background: url('@/assets/images/book-bg1.png');
      height: 141px;
      width: 100px;
      position: relative;
      .books-title{
        position: absolute;
        left: 15px;
        top: 17px;
        text-align: center;
        width: 22px;
        height: 97px;
        font-family: STBaoliTC, STBaoliTC;
        font-weight: 400;
        font-size: 12px;
        color: #363636;
        line-height: 12px;

        // 可选：如果需要文字在容器内垂直居中
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
      }
    }
  }
}
</style>